package com.xywy.beautyand.util;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;

 

/**
 * ����ϵͳ��Ƭ�Ĺ�����
 * 
 * @author ...
 * @version 1.0
 */
public class PhotoUtil {
	private static String tag = PhotoUtil.class.getSimpleName();
	

/**
 * ����ϵͳ����������������Ƭ
 * 
 * @param activity
 *            ���ø÷����Ľ���
 * @return photo ����������Ƭ
 */
	public static File getPhotoByTaking(Activity activity) {
		File photo = FileUtil.generateFile("jpg");// �����ļ�,���������ɺ󷵻ص���Ƭ
		Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
		intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
		activity.startActivityForResult(intent, Constants.PHOTO_GRAPH);
		return photo;
	}

	/**
	 * ����ϵͳ����������Ƭ
	 * 
	 * @param activity
	 *            ���ø÷����Ľ���
	 */
	public static void getPhotoFromAlbum(Activity activity) {
		Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
		intent.setType("image/*");
		activity.startActivityForResult(intent,Constants.ALB_UM);
	}

	
	/**
	 * ͨ����Ƭ��uri��ѯϵͳ�������Ƭ���ݿ�?��ȡ����·��
	 * 
	 * @param activity
	 * @param uri
	 * @return
	 */
	public static String getPathByUri(Activity activity, Uri uri) {
		String[] projection = { MediaStore.Images.Media.DATA };
		Cursor cursor = activity
				.managedQuery(uri, projection, null, null, null);
		int column_index = cursor
				.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
		cursor.moveToFirst();
		return cursor.getString(column_index);
	}
	

}
